﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using rock.UI.common;
using rock.DAL;
using rock.UI.pictureinfo;
 

namespace rock.UI.picturexml
{
    //错误	23	未能找到类型或命名空间名称“ScriptManager”(是否缺少 using 指令或程序集引用?)	E:\VS2010\SVN\RentalHousingManager\rockpear\RentalHousingManager2\RentalHousingManager2\UI\picturexml\UserControlTestWebView.cs	20	50	rock

 
    public partial class UserControlTestWebView : UserControl
    {
      
        public UserControlTestWebView()
        {
            InitializeComponent();
             
            
        }

        public String filename;
        private void UserControlTestWebView_Load(object sender, EventArgs e)
        {
            
        }  

        public void loadHtml() {
            webBrowser1.ObjectForScripting = new ScriptManager(this);  
            //this.webBrowser1.Navigate("file:///E:/VS2010/SVN/RentalHousingManager/rockpear/RentalHousingManager2/RentalHousingManager2/UI/picturexml/picture_xml/"+filename);
            this.webBrowser1.Navigate( filename);
        }


         [ComVisible(true)]
         public class ScriptManager
         {
             private UserControlTestWebView mForm;

             public ScriptManager(UserControlTestWebView form)
             {
                 mForm = form;
             }

            

             public String AnotherMethod(string message)
             {
                 MessageBox.Show(message);
                 return "i am catch";
             }

             public int inits(String _HOUSE_CODE)
             {
                 int houseStatus = -1;
                 //SQL LOAD DETAIL
                 if (_HOUSE_CODE != null && !_HOUSE_CODE.Equals(""))
                 {
                     String sql = @"SELECT STATUS  FROM HOUSE_ROOM WHERE  HOUSE_ROOM.HOUSE_CODE = '{0}'";

                     DataSet statusDs = DbHelperSQL.Query(String.Format(sql, _HOUSE_CODE));

                     if (statusDs != null && statusDs.Tables.Count > 0 && statusDs.Tables[0].Rows.Count > 0)
                     {
                         int status = (int)statusDs.Tables[0].Rows[0]["STATUS"];
                         houseStatus = status;
                     }
                     else
                     {
                         //没有找到房子
                         houseStatus = Constant.HOUSE_ROOM_STATUS_NORECORD;
                     }
                 }
                 else
                 {
                     houseStatus = Constant.HOUSE_ROOM_STATUS_NOHOUSE_CODE;
                 }
                 return houseStatus;
             }

             public void show(String id, int houseStatus)
             {
                 if (houseStatus == Constant.HOUSE_ROOM_STATUS_UNRENT
                 || houseStatus == Constant.HOUSE_ROOM_STATUS_RENTED
                 || houseStatus == Constant.HOUSE_ROOM_STATUS_YUDING
                 || houseStatus == Constant.HOUSE_ROOM_STATUS_PAUSE
                 )
                 {
                     String sql = @"SELECT SEQID , STATUS  FROM HOUSE_ROOM WHERE  HOUSE_ROOM.HOUSE_CODE = '{0}'";
                     DataSet statusDs = DbHelperSQL.Query(String.Format(sql, id));

                     if (statusDs != null && statusDs.Tables.Count > 0 && statusDs.Tables[0].Rows.Count > 0)
                     {
                         int seqid = (int)statusDs.Tables[0].Rows[0]["SEQID"];
                         Form1HouseDetailInfo form = new Form1HouseDetailInfo();
                         form._ROOM_SEQID = seqid;
                         form.userControlRoomAllInfo1._ROOM_SEQID = seqid;
                         form.ShowDialog(this.mForm);
                     }
                     else
                     {
                         MessageBox.Show("没有找到数据库记录信息.ID:" + id + ";STATUS" + houseStatus, "提示");
                     }
                 }
                 else
                 {
                     MessageBox.Show("没有找到房间信息,请先点击页面顶部的刷新按钮刷新数据.ID:" + id + ";STATUS" + houseStatus, "提示");
                 }

             }

         }

         private void webBrowser1_VisibleChanged(object sender, EventArgs e)
         {
             if (this.webBrowser1.Visible) {
                 loadHtml();
             }
             
         }

   
    }
}
